package top.zuli.package01.class16;

import org.junit.Test;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;

public class Demo {
    /*
     * 计算当前时间距离2012年 12月12日过了多少天
     * */
    @Test
    public void test1(){
        //传统日期计算
        Date date = new Date();
        long end = date.getTime();

        Calendar calendar = Calendar.getInstance();
        calendar.set(2012,11,12);
        long start = calendar.getTime().getTime();

        long result = end-start;
        System.out.println(result/1000/60/60/24);
        //jdk8新增日期计算
        long day = ChronoUnit.DAYS.between(LocalDate.of(2012, 12, 12), LocalDate.now());
        System.out.println(day);
    }
}

/*
public class Demo {
    @Test
    public void test1(){
        Date date = new Date();
        long end = date.getTime();

        Calendar calendar = Calendar.getInstance();
        calendar.set(2012,11,12);
        long start = calendar.getTime().getTime();

        long result = end-start;
        System.out.println(result/1000/60/60/24);
        long day = ChronoUnit.DAYS.between(LocalDate.of(2012, 12, 12), LocalDate.now());
        System.out.println(day);
    }
}
*/
